<?php
$loginUsername = isset($_POST["loginUsername"]) ? $_POST["loginUsername"] : "";
$loginPassword = $_POST["loginPassword"];
include 'open-connection.php';

// Performing SQL query
$query = "SELECT COUNT(*) AS NUM FROM medico WHERE medico.usuario = '$loginUsername' AND medico.clave = '$loginPassword'";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
	$arr[] = $line;
}

include 'close-connection.php';
 
if($arr[0]["NUM"] > 0){
	session_register($loginUsername);
	session_register($loginPassword); 
	//header("location:login_success.php");
    echo "{success: true, loginUsername:'$loginUsername'}";
} else {
    echo "{success: false, errors: { reason: 'Clave o nombre de Usuario inv&aacute;lido. Intente nuevamente.' }}";
}
?>